package com.duyj.rule.rhino;


import com.duyj.rule.model.datarow.DataRow;


/**
 * @author Think
 */
public class DataRowAccessScriptableObject extends AbstractBizScriptableObject {
    private static final String SCRIPT_NAME = "draso";

    private DataRow dataRow;

    public DataRowAccessScriptableObject(DataRow dataRow) {
        this.dataRow = dataRow;
    }

    @Override
    public String defineUniqueObjectName() {
        return SCRIPT_NAME;
    }

    @Override
    public String buildScriptableJs() {
        return String.format("getColumnDataValue = function(tableName,columnName){ return %s.getColumnDataValue(tableName,columnName); };", SCRIPT_NAME);
    }

    /**
     * 从dataRow中取值的通用函数
     *
     * @param tableName
     * @param columnName
     * @return
     */
    public Object getColumnDataValue(String tableName, String columnName) {
        return dataRow.findDataRow(tableName).getColumnValue(columnName);
    }

}
